<?php

$json = array("success" => false, "msj" => "Imposible creación");
$role = json_decode(filter_input(INPUT_POST, 'role_'));  
if($role != NULL)
{ 
    $role_name = $role[0]; 
    $query_crear = $role[1]; 
     
    $privs = $role[2];
    $roless = $role[3];
    $Run_ = fopen("run2Role.sql", "w+") or die("no abrió run.sql");  
    $str_run = $query_crear."\n";   
    foreach ($privs as $p)
        $str_run.= "GRANT ".$p." TO ".$role_name.";\n";
    foreach ($roless as $r)
        $str_run.= "GRANT ".$r." TO ".$role_name.";\n";
    fwrite($Run_, $str_run); 
    fclose($Run_);
    exec("cmd2_.bat");
    $json['success'] = true;
    $json['msj'] = "Rol Creado Con Exito";
}
print( json_encode($json));